#include <stdio.h>
#include <stdlib.h>

#define NIL NULL
typedef int HashVal; /* 默认散列值为int型 */
typedef HashVal Position; /* 数组下标是元素的位置 */
typedef int ElemSet; /* 默认数据类型是整数 */
typedef enum {Empty, Active, Inactive} Status; /* 三种状态 */

typedef struct RecordNode *Records;
struct RecordNode {
    ElemSet key; /* 关键字 */
    /* 其他属性由用户自定义 */
};

typedef struct DataNode {
    Records data; /* 数据 */
    Status status; /* 该数据的状态 */
} DataSet;

typedef struct HashNode *HashTable;
struct HashNode {
    DataSet *ht; /* 散列表数据 */
    int size; /* 散列表当前数据元素个数 */
    int table_size; /* 散列表表长 */
};

HashTable InitHashTable(int table_size) {
    HashTable htable;
    int i;

    htable = (HashTable)malloc(sizeof(struct HashNode));
    htable->ht = (DataSet *)malloc(sizeof(DataSet) * table_size);
    for (i = 0; i < table_size; i++) {
        htable->ht[i].data = NIL;
        htable->ht[i].status = Empty;
    }
    htable->table_size = table_size;
    htable->size = 0;

    return htable;
}

HashVal Hash(ElemSet key, int table_size) {
    return key % table_size;
}

Position SolveCollision(ElemSet key, int count) {
    return 1;
}

/* 算法11-11：开放定址法散列查找 SearchHash(htable, key) */
Position SearchHash(HashTable htable, ElemSet key) {
    HashVal hash_v;
    Position p;
    int count;

    hash_v = Hash(key, htable->table_size); /* 求得散列地址 */
    p = hash_v;
    count = 0; /* 记录冲突次数 */
    while (htable->ht[p].status != Empty && htable->ht[p].data->key != key) {
        count++; /* 记录1次冲突 */
        p += SolveCollision(key, count); /* 求下一探查地址 */
        if (p >= htable->table_size) {
            p %= htable->table_size;
        }
    }
    return p; /* 这时 htable.ht[p].data.key=key或 htable.ht[p].status=Empty */
}
/* 算法11-11 结束 */

/* 算法11-12：开放定址法散列插入 InsertHash(htable, x) */
void InsertHash(HashTable htable, Records x) {
    Position p;

    p = SearchHash(htable, x->key);
    if (htable->ht[p].status != Active) {
        htable->ht[p].data = x;
        htable->ht[p].status = Active;
        htable->size++;
    }
}
/* 算法11-12 结束 */

int main(void) {
    HashTable htable;
    int table_size, n, i;
    Records x;

    scanf("%d", &table_size);
    htable = InitHashTable(table_size);
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        x = (Records)malloc(sizeof(struct RecordNode));
        scanf("%d", &x->key);
        InsertHash(htable, x);
    }
    for (i = 0; i < htable->table_size; i++) {
        if (htable->ht[i].status == Active) {
            printf("ht[%d] = %d\n", i, htable->ht[i].data->key);
        }
    }
    return 0;
}